package com.huanglaoshi.java.io;

import java.io.File;

import org.junit.Test;

/**
 * 2:文件检测
 * @author Administrator
 *
 */
public class File02CheckDemo {
	
	@Test
	public void exists01() throws Exception {
		File f01 = new File("D:/io/helloWorldIO.txt");
		boolean flag =f01.exists();
		System.out.println(flag);
		if(flag){
			System.out.println("文件或者文件夹存在...");
		}else{
			System.out.println("文件或者文件夹不存在...");
		}
	}
	
	@Test
	public void exists02() throws Exception {
		//指的是当前目录下的io1521: 当前目录表示 huanglaoshi-java-demo 
		//E:\xx1609\huanglaoshi-java-demo
		File f01 = new File("io1521/helloWorldIO.txt");
		boolean flag =f01.exists();
		System.out.println(flag);
		if(flag){
			System.out.println("文件或者文件夹存在...");
		}else{
			System.out.println("文件或者文件夹不存在...");
		}
		System.out.println(f01.getAbsolutePath());
		
	}
	
	@Test
	public void exists03() throws Exception {
		//指的是根目录下的io1521: 根目录指的是文件夹huanglaoshi-java-demo所在的根目录 也就是E盘 
		File f01 = new File("/io1521/helloWorldIO.txt");
		boolean flag =f01.exists();
		System.out.println(flag);
		if(flag){
			System.out.println("文件或者文件夹存在...");
		}else{
			System.out.println("文件或者文件夹不存在...");
		}
		System.out.println(f01.getAbsolutePath());
		
	}
	
	@Test
	public void exists04() throws Exception {
		File f01 = new File("ioXDLJ");
		boolean flag =f01.exists();
		System.out.println(flag);
		if(flag){
			System.out.println("文件或者文件夹存在...");
		}else{
			System.out.println("文件或者文件夹不存在...");
		}
		System.out.println(f01.getAbsolutePath());
		
	}
	
	@Test
	public void canWrite() throws Exception {
		//指的是根目录下的io1521: 根目录指的是文件夹huanglaoshi-java-demo所在的根目录 也就是E盘 
		File f01 = new File("io1521/helloWorldIO.txt");
		boolean flag =f01.canWrite();
		System.out.println(flag);
		if(flag){
			System.out.println("文件可写...");
		}else{
			System.out.println("文件不可写 也就是文件是只读的...");
		}
		
	}
	@Test
	public void isFile() throws Exception {
		//指的是根目录下的io1521: 根目录指的是文件夹huanglaoshi-java-demo所在的根目录 也就是E盘 
		File f01 = new File("io1521/helloWorldIO.txt");
		boolean flag01 =f01.isFile();
		System.out.println(flag01);
		if(flag01){
			System.out.println(f01.getAbsolutePath()+"是1个文件...");
		}else{
			System.out.println(f01.getAbsolutePath()+"不是1个文件...");
		}
		
		File f02 = new File("io1521/directory88");
		boolean flag02 =f02.isFile();
		System.out.println(flag02);
		if(flag02){
			System.out.println(f02.getAbsolutePath()+"是1个文件...");
		}else{
			System.out.println(f02.getAbsolutePath()+"不是1个文件...");
		}
		
	}
	@Test
	public void isDirectory() throws Exception {
		//指的是根目录下的io1521: 根目录指的是文件夹huanglaoshi-java-demo所在的根目录 也就是E盘 
		File f01 = new File("io1521/helloWorldIO.txt");
		boolean flag01 =f01.isDirectory();
		System.out.println(flag01);
		if(flag01){
			System.out.println(f01.getAbsolutePath()+"是1个文件夹...");
		}else{
			System.out.println(f01.getAbsolutePath()+"不是1个文件夹...");
		}
		
		File f02 = new File("io1521/directory88");
		boolean flag02 =f02.isDirectory();
		System.out.println(flag02);
		if(flag02){
			System.out.println(f02.getAbsolutePath()+"是1个文件夹...");
		}else{
			System.out.println(f02.getAbsolutePath()+"不是1个文件夹...");
		}
		
	}

}
